namespace LightCAD.Core.Elements
{
    public class Point : LcElement
    {
        public Vector2d P;
        public Point()
        {
        }
        public Point(Vector2d p)
        {
            this.P = p;
        }
        public Point(double x, double y)
        {
            this.P.X = x;
            this.P.Y = y;
        }

        public override LcElement Clone()
        {
            var clone = new Point();
            clone.Copy(this);
            return clone;
        }

        public override void Copy(LcElement src)
        {
            base.Copy(src);
            this.P = ((Point)src).P;
        }
        private double GetAngel(Vector2d p, Vector2d basep)
        {
            int X = Convert.ToInt32(p.X);
            int Y = Convert.ToInt32(p.Y);

            Vector2d a1 = new Vector2d(X, Y);
            Vector2d a2 = new Vector2d(X, 300);
            Vector2d b1 = new Vector2d(X, Y);
            Vector2d b2 = new Vector2d(basep.X, basep.Y);
            var a = Math.Atan2(a2.Y - a1.Y, a2.X - a1.X);
            var b = Math.Atan2(b2.Y - b1.Y, b2.X - b1.X);
            double angle = 180 * (b - a) / Math.PI;
            return (angle > 0 ? angle : angle + 360);
        }
        public override void Scale(Vector2d factor, double length)
        {
            Matrix3d matrix3 = Matrix3d.Scale(length, factor);
            this.P = matrix3.MultiplyPoint(this.P);
        }

        public void Set(Vector2d? p, bool fireChangedEvent = false)
        {
            //PropertySetter:P
            if (!fireChangedEvent)
            {
                if (p != null) this.P = p.Value;
            }
            else
            {
                bool chg_p = (p != null && p != this.P);
                if (chg_p)
                {
                    OnPropertyChangedBefore(nameof(P), this.P, p);
                    var oldValue = this.P;
                    this.P = p.Value;
                    OnPropertyChangedAfter(nameof(P), oldValue, this.P);
                }
            }
        }





    }
}